<?php
/*
Plugin Name: Nube Comments - Widget
Plugin URI: http://cinefilo.homelinux.net/blog/plugin-wordpress/nube-comments-widget/
Description: Widget version of plugin <a href="http://www.anieto2k.com/mis-plugins/nube-comments/">Nube Comments</a>.
Author: Luis P&eacute;rez (cinefilo)
Version: 2.3
Author URI: http://cinefilo.homelinux.net/blog


  Copyright (c) 2006 by Luis Perez (cinefilo) (email : cinefilo@gmail.com) 
  
  http://www.gnu.org/copyleft/gpl.html

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Credits

	This widget use plugin Nube Comments release by Andres Nieto [http://www.anieto2k.com/mis-plugins/nube-comments/].

Changelog:

	- v2.3 (09-18-2006): Add support localization. Include .mo file.
	- v2.2 (09-08-2006): Add support Gettext.
	- v2.1 (06-08-2006): Add credits. Only show cloud tag in post and home.
	- v2.0 (04-08-2006): Show a cloud tag of author comments of post.
	- v1.0 (01-08-2006): Initial release. Show a cloud tag of all the authors comments of blog.

 */
 
/* Localization */
$domain = 'nube_comments_widget'; 

$ncw_path = 'wp-content/plugins/widgets/';

load_plugin_textdomain($domain,$ncw_path);

function widget_nube_comments_init() {

	if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
		return;

	function widget_nube_comments($args){

		extract($args);
		$options = get_option( 'widget_nube_comments' );
		$title = $options['title'];
		$min = $options['min'];
		$max = $options['max'];
		$limit = $options['limit'];		


		if( is_single() && (function_exists('nube_comments')) ) {
			echo $before_widget . $before_title . $title. $after_title; // los comentaristas del post
			nube_comments($min,$max);
			echo $after_widget;			
		}
		if ( is_home() && (function_exists('nube_todos'))) { // todos los comentaristas
			echo $before_widget . $before_title . $title. $after_title;
			nube_todos($min,$max,$limit);
			echo $after_widget;			
		}

	}
	function widget_nube_comments_control(){
		
		global $domain;
		
		$options = get_option( 'widget_nube_comments' );
		if (!is_array( $options )) {
			$options = array( 'title' => 'Nube Comments','min' => 8, 'max' => 30, 'limit' => 20 );
		}

		if ($_POST['nube_comments-submit']) {
			$options['title'] = strip_tags(stripslashes($_POST['nube_comments-title']));
			$options['min'] = strip_tags(stripslashes($_POST['nube_comments-min']));
			$options['max'] = strip_tags(stripslashes($_POST['nube_comments-max']));
			$options['limit'] = strip_tags(stripslashes($_POST['nube_comments-limit']));
			
			update_option( 'widget_nube_comments', $options );
		}

		$title = htmlspecialchars($options['title'], ENT_QUOTES);
		$min = htmlspecialchars($options['min'], ENT_QUOTES);
		$max = htmlspecialchars($options['max'], ENT_QUOTES);
		$limit = htmlspecialchars($options['limit'], ENT_QUOTES);
?>


		<p><?php _e('Title:',$domain); ?><input style="width: 230px;" type="text" id="nube_comments-title" name="nube_comments-title" value="<?php echo $title ?>" /></p>
		<p style="text-align:right;margin-right:40px;"><?php _e('Min:',$domain); ?> <input type="text" id="nube_comments-min" name="nube_comments-min" value="<?php echo $min ?>" size="3" maxlength="3" /></p>
		<p style="text-align:right;margin-right:40px;"><?php _e('Max:',$domain); ?> <input type="text" id="nube_comments-max" name="nube_comments-max" value="<?php echo $max ?>" size="3" maxlength="3" /></p>
		<p style="text-align:right;margin-right:40px;"><?php _e('Limits of authors:',$domain); ?><input type="text" id="nube_comments-limit" name="nube_comments-limit" value="<?php echo $limit ?>" size="3" maxlength="3"/></p>
		<input type="hidden" id="nube_comments-submit" name="nube_comments-submit" value="1" />
<?php
	}

	register_sidebar_widget( 'Nube Comments', 'widget_nube_comments' );
	register_widget_control( 'Nube Comments', 'widget_nube_comments_control', 300,200 );
}

add_action( 'plugins_loaded', 'widget_nube_comments_init' );

?>
